package com.lixinlei.springboot_servlet.controller.requestmapping.param;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/request/mapping/params")
public class ParamController {

    @RequestMapping(path = "/path1", method = RequestMethod.GET, params = {"agree=true"})
    public String path1() {
        System.out.println("************************path1()");
        return "GET : path1()";
    }

    /**
     * key : value 以 form-data 和 x-www-form-urlencoded 的格式提交都是可以的
     * @return
     */
    @RequestMapping(path = "/path2", method = RequestMethod.POST, params = {"agree=true"})
    public String path2() {
        System.out.println("************************path2()");
        return "POST : path2()";
    }

    /**
     * 要求请求的参数中必须有 agree，对 agree 的值不做要求；
     * @return
     */
    @RequestMapping(path = "/path3", method = RequestMethod.POST, params = {"agree"})
    public String path3() {
        System.out.println("************************path3()");
        return "POST : path3()";
    }

    @RequestMapping(path = "/path4", method = RequestMethod.POST, params = {"agree!=true"})
    public String path4() {
        System.out.println("************************path4()");
        return "POST : path4()";
    }

    /**
     * 请求的参数中不能有 agree 参数；
     * @return
     */
    @RequestMapping(path = "/path5", method = RequestMethod.POST, params = {"!agree"})
    public String path5() {
        System.out.println("************************path5()");
        return "POST : path5()";
    }

}
